import Vue from 'vue'
import VueRouter from 'vue-router'
//同步加载方式
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:"/",
    redirect:"/home"
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path:"/songList",
    name:'songList',
    //路由懒加载
    component:()=>import("../views/SongList.vue")
  },
  {
    // 搜索
    path:"/searchToll",
    name:'searchToll',
    component:()=>import("../views/SearchToll.vue")
  },
  // 热门歌手
  {
    path:"/singerFun",
    name:'singerFun',
    component:()=>import("../views/SingerFun.vue")
  },
  //排行版
  // {
  //   path:"/rankingFun",
  //   name:'rankingFun',
  //   component:()=>import("../views/RankingFun.vue")
  // },
  //排行版2
  {
    path:"/rankingList",
    name:'rankingList',
    component:()=>import("../views/RankingList.vue")
  },
  //每日推荐
  {
    path:"/dailySpecial",
    name:'dailySpecial',
    component:()=>import("../views/dailySpecial.vue")
  },
  //歌单广场
  {
    path:"/SongSquare",
    name:'SongSquare',
    component:()=>import("../views/SongSquare.vue")
  },
  //评论
  {
    path:"/commentFun",
    name:'commentFun',
    component:()=>import("../views/CommentFun.vue")
  },
  //登录
  {
    path: '/login',
    name: 'login',
    component: ()=>import("../components/base/LoginBase.vue")
  },
  //获取用户详情
  {
    path:"/personalCenter",
    name:'personalCenter',
    component:()=>import("../views/personalCenter.vue")
  },
  //个人中心
  // {
  //   path: '/userinfo',
  //   name: 'userinfo',
  //   component:()=>import("../views/userInfo.vue")
  // },
    // 引导页
    {
      path: '/guidePage',
      name: 'guidePage',
      component: ()=>import("../components/public/GuidePage.vue")
    },
    // 广告页
    {
      path: '/userinfo',
      name: 'userinfo',
      component: ()=>import("../views/UserInfo.vue"),
      // 独享路由守卫
      beforeEnter:(to,from,next)=>{
        let login = window.localStorage.getItem("token");
        // 判断是否登录
        if(!login){
          next("/login");
          return;
        }else{
          next();
        }
      }
    },
 
]
// 解决router重复点击报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location){
  return originalPush.call(this,location).catch(err=>err);
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
